<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>学情管理</title>
	<link rel="stylesheet" href="../css/common2.css">
</head>

<style>
	.search_img {
			position: absolute;
			right: 3%;
		}
		.table {
      table-layout: fixed; /* 固定表格布局 */
      width: 100%; /* 宽度占满父容器 */
  }

  td {
      max-width: 150px; /* 最大宽度 */
      overflow: hidden; /* 隐藏溢出 */
      text-overflow: ellipsis; /* 显示省略号 */
      white-space: nowrap; /* 防止换行 */
  }

  th {
      width: 150px; /* 设置表头列宽 */
  }
  .delete1 {
    /* width: 80px; */
    height: 35px;
    text-align: center;
    font-size: 14px;
    line-height: 35px;
    color: white;
    float: left !important;
    bottom: 50px;
    margin-left: 2%;
    cursor: pointer;
    background: url(../image/enter_long.png) no-repeat center center;
}
.uihf {
			display: flex;
}
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: white;
  width: 400px;
  height: 400px;
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.modal h3 {
  margin-bottom: 10px;
}

.modal ul {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 5px;
}

.modal ul li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}

.modal ul li:last-child {
  border-bottom: none;
}

.modal button {
  background: #007bff;
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
}

.modal button:hover {
  background: #0056b3;
}

.modal .close-btn {
  margin-top: 10px;
  background: #dc3545;
}

.modal .close-btn:hover {
  background: #c82333;
}
[v-if] {
			display: none;
		}
		
</style>
<body>

	<div id="vue-root">
		
		<div class="refresh" onclick="location.reload()" v-t="'刷新'"></div>
		
		<input placeholder="请输入学员姓名" class="search" v-model="search.name" style="position: absolute; right: 260px">
		<input placeholder="请输入手机号码" class="search" v-model="search.bindCode" style="height: 33px;">
		
		<img src="../image/search.png" height="35" width="35" alt="" class="search_img" @click="getData0">

		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th>
							<input type="checkbox" class="check-box" v-model="all">
						</th>
						<th v-t="'序号'"></th>
						<th v-t="'校区'"></th>
						<th v-t="'学员姓名'"></th>
						<th v-t="'电话号码'"></th>
						<th v-t="'性别'"></th>
						<th v-t="'年级'"></th>
						<th v-t="'学习习惯'"></th>
						<th v-t="'家长情况'"></th>
						<th v-t="'辅导建议'"></th>
						<th v-t="'编辑/删除'"></th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(student,index) in list" :key="student.id">
						<td>
							<input type="checkbox" class="check-box" v-model="student.checked">
						</td>
						<td> <span v-text="index+1"></span></td>
						<td v-text="student.schoolName"></td>
						<td v-text="student.name"></td>
						<td v-text="student.bindCode"></td>
						<td v-text="student.sex?'男':'女'"></td>
						<td  v-text="student.gradeName"></td>
						<td :title="student.learningHabit">{{ student.learningHabit }}</td>
						<td :title="student.parentalSituation">{{ student.parentalSituation }}</td>
						<td :title="student.counselingAdvice">{{ student.counselingAdvice }}</td>

						<td>
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon">
									<a :href="'xueqing_item.html?id='+student.id"
										style="position: absolute; left: 20%; top: 30%;">
										<img class="img" src="../image/edit.png" height="20" width="20"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([student.id])"
									style="position: absolute; right: 20%; top: 30%;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br>
		<form enctype="multipart/form-data" id="form" ref="form" style="display: none;">
			<input type="file" name="file" id="file" @change="importExcel" ref="file"
				accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
		</form>
		<div class="delete" @click="batchDelete" v-if="able.del" v-t="'批量删除'"></div>
		<a href="/excel/学情导入表.xls" >
			<div class="delete1 long-background-img">下载导入模板</div>
		</a>
		<label class="delete1 long-background-img" for="file" v-if="able.import">批量导入学情</label>
		<div class="delete1 long-background-img" v-if="able.export" @click="exports">批量导出学情</div>
		<div class="delete1 long-background-img"  @click="openModal">下载历史文件</div>
		<div v-if="showModal" class="modal-overlay">
			<div class="modal">
			  <h3>历史文件列表</h3>
			  <ul>
				<li v-for="file in fileList" :key="file">
					<span>{{ file }}</span>
					<a :href="'/static/' + schoolId + '/excel/' + file">
					  <button>下载</button>
					</a>
				  </li>
			  </ul>
			  <button class="close-btn" @click="closeModal">关闭</button>
			</div>
		  </div>
		  
		  
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div style="float: right;">
			总共{{total}}条记录
			<select class="ui-select init" style="height:32px" v-model="pageSize">
				<option :value="10">每页10条</option>
				<option :value="30">每页30条</option>
				<option :value="100">每页100条</option>
			</select>
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/scriptZIP/vue-select.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>
	<script src="/js/i18n.js"></script>

	<script>
var schoolId = top_params().id;
		setI18n({
			序号: 'No.',
			操作: 'operating',
			年级: 'student',
			添加年级: 'Add grade',
			刷新: 'Refresh',
			批量删除: 'batch deletion'
		});

		var app = new Vue(merge({
			data: {
				urls: {
					del: '/pc/learningSituation/del'
				},
	
				showModal: false,
      fileList: []
			},
			created: function () {
				
				if (!schoolId) {
					alert('未知学校');
					throw '未知学校';
				}
		
				this.urls.list = '/pc/learningSituation/list?schoolId=' + schoolId;
				this.urls.imports = '/pc/learningSituation/import/' +schoolId ;
				this.getData();
				abled('xueQingManagement', this);
			},
			methods:{
				exports: function () {
					var q = Qs.stringify(this.search);
					if (q) q = '&' + q;

					location.href = '/pc/learningSituation/export?schoolId=' + schoolId + q;
				},
				openModal() {
      this.showModal = true;
      this.fetchFiles();
    },
    closeModal() {
      this.showModal = false;
    },
    fetchFiles() {
      axios.get('/pc/learningSituation/getFile/'+top_params().id)
        .then(response => {
          this.fileList = response.data;
        })
        .catch(error => {
          console.error('获取文件列表失败', error);
        });
    },
    downloadFile(fileName) {
        var url = '/static/' + schoolId + '/' + fileName;
  var link = document.createElement('a');
  link.href = url;
  link.setAttribute('download', fileName); // 让浏览器以文件下载方式处理
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
    }
			},
			i18n: i18n
		}));
	</script>

</body>

</html>